using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class OrderControlCodesAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public OrderControlCodesAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"HD","HR","NA","NW","OC","OD","CA","CH","CN","CR","DC","DE","OH","OK","OR","PA","RE","RL","RO","RP","RQ","RR","RU","SC","SN","SR","SS","DR","UC","UD","UH","UM","UR","UX","XO","XR","XX","UF","FU","UA","RF","DF","OE","OF","AF"};
						validVersionCodes[HL7Version.v231] = new string[]{"NW","OK","UA","CA","OC","CR","UC","DC","OD","DR","UD","HD","OH","UH","HR","RL","OE","OR","UR","RP","RU","RO","RQ","UM","PA","CH","XO","XX","UX","XR","DE","RE","RR","SR","SS","SC","SN","NA","CN","RF","AF","DF","FU","OF","UF","LI","UN"};
						validVersionCodes[HL7Version.v24] = new string[]{"NW","OK","UA","PR","CA","OC","CR","UC","DC","OD","DR","UD","HD","OH","UH","HR","RL","OE","OR","UR","RP","RU","RO","RQ","UM","PA","CH","XO","XX","UX","XR","DE","RE","RR","SR","SS","SC","SN","NA","CN","RF","AF","DF","FU","OF","UF","LI","UN"};
						validVersionCodes[HL7Version.v25] = new string[]{"CR","DC","DE","DF","DR","FU","HD","HR","LI","NA","NW","OC","OD","OE","OF","OH","OK","RU","SC","SN","SR","SS","UA","UC","UD","UF","UH","UM","UN","UR","UX","XO","XR","XX","AF","CA","CH","OR","PA","PR","RE","RF","RL","RO","RP","RQ","RR","CN","OP","PY"};
						validVersionCodes[HL7Version.v251] = new string[]{"NW","OK","UA","PR","CA","OC","CR","UC","DC","OD","DR","UD","HD","OH","UH","HR","RL","OE","OR","UR","RP","RU","RO","RQ","UM","PA","CH","XO","XX","UX","XR","DE","RE","RR","SR","SS","SC","SN","NA","CN","RF","AF","DF","FU","OF","UF","LI","UN","OP","PY"};
						validVersionCodes[HL7Version.v26] = new string[]{"AF","CA","CH","CN","CR","DC","DE","DF","DR","FU","HD","HR","LI","NA","SN","NW or RO","NW","OC","OD","OE","OF","OH","OK","OP","OR","PA","PR","PY","RE","RF","RL","RO","RP","RQ","RR","RU","SC","SR","SS","UA","UC","UD","UF","UH","UM","UN","UR","UX","XO","XR","XX","MC"};
						validVersionCodes[HL7Version.v27] = new string[]{"AF","CA","CH","CN","CR","DC","DE","DF","DR","FU","HD","HR","LI","NA","NW","OC","OD","OE","OF","OH","OK","OP","OR","PA","PR","PY","RE","RF","RL","RO","RP","RQ","RR","RU","SC","SN","SR","SS","UA","UC","UD","UF","UH","UM","UN","UR","UX","XO","XR","XX","MC"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"Hold order request","On hold as requested","Number assigned","New Order","Order canceled","Order discontinued","Cancel order request","Child order","Combined result","Canceled as requested","Discontinue order request","Data Errors","Order held","Order accepted and OK","Released as requested","Parent order","Observations to follow","Release previous hold","Replacement order","Order replace request","Replaced as requested","Request received","Replaced unsolicited","Status changed","Send order number","Response to send order status request","Send order status request","Discontinued as requested","Unable to cancel","Unable to discontinue","Unable to put on hold","Unable to replace","Unable to release","Unable to change","Change order request","Changed as requested","Order changed, unsolicited","Unable to refill","Order refilled, unsolicited","Unable to accept order","Refill order request","Order refill request denied","Order released","Order refilled as requested","Order refille request approval"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"New order (O01)","Order accepted & OK (O02)","Unable to accept order (O02/ORR)","Cancel order request (O01)","Order canceled (O01)","Canceled as requested (O02)","Unable to cancel (O02)","Discontinue order request (O01)","Order discontinued (O01)","Discontinued as requested (O02)","Unable to discontinue (O02)","Hold order request (O01)","Order held (O01)","Unable to put on hold (O02)","On hold as requested (O02)","Release previous hold (O01)","Order released (O01)","Released as requested","Unable to release (O02)","Order replace request (O01)","Replaced unsolicited (O01)","Replacement order (O01)","Replaced as requested (O02)","Unable to replace (O02)","Parent order (O01/ORU)","Child order (O01/ORU)","Change order request (O01)","Order changed, unsol. (O01)","Unable to change (O02)","Changed as requested (O02)","Data errors (O01/O02)","Observations to follow (O01/R01)","Request received (O02)","Response to send order status request (O02(Q06)","Send order status request (O01)","Status changed (O01)","Send order number (O01)","Number assigned (O02)","Combined result (R01)","Refill order request (O01)","Order refill request approval (O02)","Order refill request denied (O02)","Order refilled, unsolicited (O01)","Order refilled as requested (O02)","Unable to refill (O02)","Link order to patient care problem or goal","Unlink order from patient care problem or goal"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"New order/service","Order/service accepted & OK","Unable to accept order/service","Previous Results with new order/service","Cancel order/service request","Order/service canceled","Canceled as requested","Unable to cancel","Discontinue order/service request","Order/service discontinued","Discontinued as requested","Unable to discontinue","Hold order request","Order/service held","Unable to put on hold","On hold as requested","Release previous hold","Order/service released","Released as requested","Unable to release","Order/service replace request","Replaced unsolicited","Replacement order","Replaced as requested","Unable to replace","Parent order/service","Child order/service","Change order/service request","\"Order/service changed, unsol.\"","Unable to change","Changed as requested","Data errors","Observations/Performed Service to follow","Request received","Response to send order/service status request","Send order/service status request","Status changed","Send order/service number","Number assigned","Combined result","Refill order/service request","Order/service refill request approval","Order/service refill request denied","\"Order/service refilled, unsolicited\"","Order/service refilled as requested","Unable to refill","Link order/service to patient care problem or goal","Unlink order/service from patient care problem or goal"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Canceled as requested","Discontinue order/service request","Data errors","Order/service refill request denied","Discontinued as requested","Order/service refilled, unsolicited","Hold order request","On hold as requested","Link order/service to patient care problem or goal","Number assigned","New order/service","Order/service canceled","Order/service discontinued","Order/service released","Order/service refilled as requested","Order/service held","Order/service accepted & OK","Replaced unsolicited","Status changed","Send order/service number","Response to send order/service status request","Send order/service status request","Unable to accept order/service","Unable to cancel","Unable to discontinue","Unable to refill","Unable to put on hold","Unable to replace","Unlink order/service from patient care problem or goal","Unable to release","Unable to change","Change order/service request","Changed as requested","Order/service changed, unsol.","Order/service refill request approval","Cancel order/service request","Child order/service","Released as requested","Parent order/service","Previous Results with new order/service","Observations/Performed Service to follow","Refill order/service request","Release previous hold","Replacement order","Order/service replace request","Replaced as requested","Request received","Combined result","Notification of order for outside dispense","Notification of replacement order for outside dispense"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"New order/service","Order/service accepted & OK","Unable to accept order/service","Previous Results with new order/service","Cancel order/service request","Order/service canceled","Canceled as requested","Unable to cancel","Discontinue order/service request","Order/service discontinued","Discontinued as requested","Unable to discontinue","Hold order request","Order/service held","Unable to put on hold","On hold as requested","Release previous hold","Order/service released","Released as requested","Unable to release","Order/service replace request","Replaced unsolicited","Replacement order","Replaced as requested","Unable to replace","Parent order/service","Child order/service","Change order/service request","Order/service changed, unsol.","Unable to change","Changed as requested","Data errors","Observations/Performed Service to follow","Request received","Response to send order/service status request","Send order/service status request","Status changed","Send order/service number","Number assigned","Combined result","Refill order/service request","Order/service refill request approval","Order/service refill request denied","Order/service refilled, unsolicited","Order/service refilled as requested","Unable to refill","Link order/service to patient care problem or goal","Unlink order/service from patient care problem or goal","Notification of order for outside dispense","Notification of replacement order for outside dispense"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Order/service refill request approval","Cancel order/service request","Child order/service","Combined result","Canceled as requested","Discontinue order/service request","Data errors","Order/service refill request denied","Discontinued as requested","Order/service refilled, unsolicited","Hold order request","On hold as requested","Link order/service to patient care problem or goal","Number assigned","filler application","Other application to filler application","New order/service","Order/service canceled","Order/service discontinued","Order/service released","Order/service refilled as requested","Order/service held","Order/service accepted & OK","Notification of order for outside dispense","Released as requested","Parent order/service","Previous Results with new order/service","Notification of replacement order for outside dispense","Observations/Performed Service to follow","Refill order/service request","Release previous hold","Replacement order","Order/service replace request","Replaced as requested","Request received","Replaced unsolicited","Status changed","Response to send order/service status request","Send order/service status request","Unable to accept order/service","Unable to cancel","Unable to discontinue","Unable to refill","Unable to put on hold","Unable to replace","Unlink order/service from patient care problem or goal","Unable to release","Unable to change","Change order/service request","Changed as requested","Order/service changed, unsol.","Miscellaneous Charge - not associated with an order"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Order/service refill request approval","Cancel order/service request","Child order/service","Combined result","Canceled as requested","Discontinue order/service request","Data errors","Order/service refill request denied","Discontinued as requested","Order/service refilled, unsolicited","Hold order request","On hold as requested","Link order/service to patient care problem or goal","Number assigned","New order/service","Order/service canceled","Order/service discontinued","Order/service released","Order/service refilled as requested","Order/service held","Order/service accepted & OK","Notification of order for outside dispense","Released as requested","Parent order/service","Previous Results with new order/service","Notification of replacement order for outside dispense","Observations/Performed Service to follow","Refill order/service request","Release previous hold","Replacement order","Order/service replace request","Replaced as requested","Request received","Replaced unsolicited","Status changed","Send order/service number","Response to send order/service status request","Send order/service status request","Unable to accept order/service","Unable to cancel","Unable to discontinue","Unable to refill","Unable to put on hold","Unable to replace","Unlink order/service from patient care problem or goal","Unable to release","Unable to change","Change order/service request","Changed as requested","Order/service changed, unsol.","Miscellaneous Charge - not associated with an order"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
